<?
    /* -*- Mode: PHP5; tab-width: 4; indent-tabs-mode: nil; basic-offset: 4 -*- */

    /*********************************************************
    *            --== InArch ==--
    *
    * @author Kulikov Alexey <a.kulikov@gmail.com>
    * @version n/a
    * @copyright essentialmind.com 2005
    *
    *********************************************************/
    
    /***
    * Class clientNodeFolder
    ****
    * This classs represents a folder
    ****
    * @package clientNodes
    * @author A Kulikov <a.kulikov@gmail.com>
    * @version n/a
    * @copyright essentialmind.com 2005
    ***/
    class clientNodeTag extends clientNode{
        
        private $pageType;
        
        /**
         * Process inputs
         * 
         * @return void 
         **/
        public function process(){
            
            //first figure out the ID of the datatype responsible for inserats
            $this->setPageType();
                                    
            //get news items for this folder
            /*
                the call to get the full path to the node may be
                a bit costly. This procedure may need refactoring
            */            
            $items   = $this->db->getAll("SELECT 
                                                    pm.id               AS page_id,
                                                    pm.created          AS intime,
                                                    pm.title            AS title,
                                                    ni.*, 
                                                    get_path(pm.nodeid)||pm.pageurl||'.html' AS url,
                                                    'files/pages/".$this->pageType."__'||ni.id||'/' AS image_path
                                                FROM tag_page_map
                                                LEFT JOIN pagemap AS pm ON tag_page_map.page_id = pm.id
                                                LEFT JOIN node_shop_article AS ni ON pm.pageid  = ni.id
                                                WHERE 
                                                    tag_page_map.tag_id = " . $this->reference. " 
                                                    AND pm.pagetype     = " . $this->pageType . "
                                                    AND pm.wf_state     = 1
                                                ORDER BY random()");
            
            //get folder properties if any
            $data    = $this->db->getRow("SELECT * FROM tags WHERE id = ".$this->object);
            
            //get actual folder data
            //assign all this stuff to smarty
            $this->smarty->assign(array(
                                    'tag'	    => true,
                                    'items'         => $items,
                                    'data'          => $data));
            
        }
        
        /**
         * set the action template
         * 
         * @return void
         **/
        public function setTemplate(){
            $this->setActionTemplate('shopFolder.html');
        }
        
        
        /**
         * Sets the ID of the pagetype corresponsing to an inserat
         *
         */
        private function setPageType(){
            $this->pageType = (int)$this->db->getOne("SELECT id FROM datatype WHERE lower(codeset) = 'shoparticle'");
            if($this->pageType == 0){
                throw new Exception("No Shop Folder Item Datatype Registered with the system!");   
            }
        }
    }
?>